package com.hxd.otc.module.wallet.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.module.wallet.contract.ModifyWalletContactContract;
import com.hxd.otc.module.wallet.presenter.ModifyWalletContactPresenter;
import com.hxd.otc.widget.ModifyWalletContactAddressView;
import com.hxd.otc.widget.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/9/18 0018.
 * description ${修改钱包联系人、钱包联系人详情}
 */
public class ModifyWalletContactActivity extends BaseActivity<ModifyWalletContactPresenter> implements ModifyWalletContactContract.IView {

    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.et_name)
    EditText mEtName;
    @BindView(R.id.ll_coin_address)
    LinearLayout mLlCoinAddress;
    private String[] mCoinTypes = new String[]{"UES", "USDC", "BTC", "ETH"};
    private String name;

    private int mPageState = 0;

    public static final int PAGE_STATE_READ = 0;
    public static final int PAGE_STATE_ADD = 1;
    public static final int PAGE_STATE_MODIFY = 2;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_modify_wallet_contact;
    }

    @Override
    protected ModifyWalletContactPresenter createPresenter() {
        return new ModifyWalletContactPresenter(this);
    }

    @Override
    protected void initView() {
        switch (mPageState) {
            case PAGE_STATE_ADD:
                updateUIofAdd();
                break;
            case PAGE_STATE_MODIFY:
                updateUIofModify();
                break;
            case PAGE_STATE_READ:
            default:
                updateUIofRead();
                break;
        }

        mTvName.setText(name);
        mEtName.setText(name);

        mLlCoinAddress.removeAllViews();
        for (String coinType : mCoinTypes) {
            ModifyWalletContactAddressView addressView = new ModifyWalletContactAddressView(this);
            addressView.updateCoinType(coinType);
            mLlCoinAddress.addView(addressView);
        }
    }

    private void updateUIofAdd() {
        mTitleBar.setTitleText(getString(R.string.my_add_contacts));
        mTitleBar.getRightText().setText(getString(R.string.complete));
        mTvName.setVisibility(View.GONE);
        mEtName.setVisibility(View.VISIBLE);
    }

    private void updateUIofModify() {
        mTitleBar.setTitleText(getString(R.string.my_modify_contacts));
        mTitleBar.getRightText().setText(getString(R.string.complete));
        mTvName.setVisibility(View.VISIBLE);
        mEtName.setVisibility(View.GONE);

    }

    private void updateUIofRead() {
        mTitleBar.setTitleText(getString(R.string.my_contacts));
        mTitleBar.getRightText().setText(getString(R.string.my_modify));
        mTvName.setVisibility(View.VISIBLE);
        mEtName.setVisibility(View.GONE);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
